package com.zqh.productskucud.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zqh.myfmmall.entity.ProductSku;
import com.zqh.myfmmall.result.Result;
import com.zqh.productskucud.service.ProductSkuCUDService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description :
 * @Author :kono淇杭哒、
 * @Create 2022-02-18 2:15
 */
@RestController
@RequestMapping("productSku")
public class ProductSkuCUDController{
    @Autowired
    private ProductSkuCUDService productSkuCUDService;


    @PostMapping("create")
    public Result add(@RequestBody ProductSku productSku){
        return null;
    }

    @PutMapping("update")
    public Result update(@RequestBody ProductSku productSku){
        return null;
    }

//    feign请求体传集合参数报错，未解决,先改为通过传集合json字符串来实现
    @PostMapping("updateBatch")
    public Result updateBatch(@RequestBody List<ProductSku> productSkus){
        return productSkuCUDService.updateBatchById(productSkus) ? Result.success() : Result.internalServerError();
    }

    /**
     * 功能描述:
     * 提交订单服务，超时未支付服务调用，修改库存等
     * @param null
     * @return
     * @author kono曾淇杭哒！
     * @date 2022/3/4 23:16
     */
    /*@PutMapping("updateBatch")
    public Result udateBatch(@RequestBody String productSkusJsonString) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        JavaType javaType = objectMapper.getTypeFactory().constructParametricType(List.class, ProductSku.class);
        List<ProductSku> productSkus= objectMapper.readValue(productSkusJsonString,javaType);
        return productSkuCUDService.updateBatchById(productSkus) ? Result.success() : Result.internalServerError();
    }*/

    @PostMapping("delete")
    public Result delete(@RequestBody ArrayList<String> ids){
        return productSkuCUDService.removeByIds(ids) ? Result.success() : Result.internalServerError();

    }


}
